//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.lyq.bean.service;

import com.lyq.bean.Course;
import com.lyq.bean.Student;
import com.lyq.bean.mySql.AddS_Sql;
import com.lyq.bean.mySql.PlusResidueNum_Sql;
import com.lyq.bean.mySql.RemoveS_Sql;
import com.lyq.bean.mySql.SeekAllS_Sql;
import com.lyq.bean.mySql.SeekExist_Sql;
import com.lyq.bean.mySql.SeekS_Sql;
import com.lyq.bean.mySql.UpdateS_Sql;
import java.util.List;

public class S_Service {
    public S_Service() {
    }

    public Boolean add_S(String No, String name, String sex, String age, String collage, String department, String pwd,String campus,Double gpa,int major_id,int year_id) {
        Boolean bool = (new SeekExist_Sql()).seekExist_Sql(No, "学生");
        if (bool) {
            bool = false;
        } else {
            bool = (new AddS_Sql()).addS_Sql(No, name, sex, age, collage, department, pwd,campus,gpa,major_id,year_id);
        }

        return bool;
    }

    public List<Student> seekAll_S(List<Student> list) {
        List<Student> lt = (new SeekAllS_Sql()).seekAllS_Sql(list);
        return lt;
    }

    public Boolean remove_S(String sNo) {
        Boolean bool = (new RemoveS_Sql()).removeS_Sql(sNo);
        List<Course> list = (new E_Service()).seek_ElectC(sNo);

        for(int i = 0; i < list.size(); ++i) {
            String cNo = ((Course)list.toArray()[i]).getNo();
            (new PlusResidueNum_Sql()).plusResidueNum_Sql(cNo);
            bool = (new E_Service()).recede_C(cNo, sNo);
        }

        return bool;
    }

    public List<Student> seek_S(String select, String seek, String name, List<Student> list) {
        if (select.equals("学号")) {
            select = "S_No";
        } else if (select.equals("姓名")) {
            select = "S_Name";
        } else if (select.equals("所在学院")) {
            select = "S_Collage";
        }

        List<Student> lt = (new SeekS_Sql()).seekS_Sql(select, seek, name, list);
        return lt;
    }

    public Boolean updateStuInfo(String No, String name, String sex, String age, String collage, String department, String pwd) {
        Boolean bool = (new UpdateS_Sql()).updateS_Sql(No, name, sex, age, collage, department, pwd);
        return bool;
    }
    
    // 添加更新学生GPA的方法
    public Boolean updateStudentGPA(String No, double gpa) {
        Boolean bool = (new UpdateS_Sql()).updateStudentGPA(No, gpa);
        return bool;
    }


    public List<Student> getStudentsByMajorAndYear(int majorId, int yearId, List<Student> list) {
        List<Student> list1;
        list1 = (new SeekS_Sql()).getStudentsByMajorAndYear(majorId, yearId, list);
        return list1;
    }
}